//
//  CRSpecialNewsTableViewCell.m
//  NewAge
//
//  Created by dllo on 15/11/28.
//  Copyright © 2015年 ColorRevolution. All rights reserved.
//

#import "CRSpecialNewsTableViewCell.h"
#import "CRNewsModel.h"

@implementation CRSpecialNewsTableViewCell

#pragma mark - createCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}



#pragma mark - createCell

- (void)createCell {
    [self.contentView addSubview:self.leftImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.typeLabel];
    [self.contentView addSubview:self.lineView];
}



#pragma mark - lazyLoad

- (UIImageView *)leftImageView {
    if (!_leftImageView) {
        self.leftImageView = [[UIImageView alloc] init];
    }
    return _leftImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _titleLabel;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        self.contentLabel = [[UILabel alloc] init];
        _contentLabel.font = [UIFont systemFontOfSize:14];
        _contentLabel.numberOfLines = 0;
        _contentLabel.textColor = [UIColor colorWithRed:0.604f green:0.604f blue:0.604f alpha:1.00f];
    }
    return _contentLabel;
}

- (UILabel *)typeLabel {
    if (!_typeLabel) {
        self.typeLabel = [[UILabel alloc] init];
        //        _replyCountLabel.font = [UIFont fontWithName:@"ArialRoundedMTBold" size:14];
        _typeLabel.layer.borderWidth = 0.7;
        _typeLabel.layer.borderColor = [[UIColor colorWithRed:0.929f green:0.106f blue:0.149f alpha:0.50f] CGColor];
        _typeLabel.layer.cornerRadius = 2;
        _typeLabel.font = [UIFont systemFontOfSize:11];
        _typeLabel.textColor = [UIColor redColor];
        _typeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _typeLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        self.lineView = [[UIView alloc] init];
        _lineView.backgroundColor =  [UIColor colorWithRed:0.871f green:0.871f blue:0.871f alpha:0.50f];
    }
    return _lineView;
}

#pragma mark - Setter Method

- (void)setNews:(CRNewsModel *)news {
    if (_news != news) {
        _news = news;
        [self changeValue];
    }
}

- (void)changeValue {
    [_leftImageView sd_setImageWithURL:[NSURL URLWithString:_news.imgsrc] placeholderImage:nil];
    _titleLabel.text = _news.title;
    
    NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:_news.digest];
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:8 * HEIGHT / 667.0];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_news.digest length])];
    _contentLabel.attributedText = attributedString;
    _typeLabel.text = @"专题";
}



#pragma mark - SetLayout

- (void)layoutSubviews {
    [super layoutSubviews];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        Left(self.contentView.mas_left, 7 * HEIGHT / 667.0);
        Top(self.contentView.mas_top, 12 * HEIGHT / 667.0);
        Bottom(self.contentView.mas_bottom, -12 * HEIGHT / 667.0);
        Right(_titleLabel.mas_left, -5 * WIDTH / 375.0);
        WequalNum(100 * WIDTH / 375.0);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Left(_leftImageView.mas_right, 5 * WIDTH / 375.0);
        Top(self.contentView.mas_top, 12 * HEIGHT / 667.0);
        Right(self.contentView.mas_right, -5 * WIDTH / 375.0);
        HequalNum(25);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Left(_leftImageView.mas_right, 5);
        Top(_titleLabel.mas_bottom, 0 * HEIGHT / 667.0);
        Right(self.contentView.mas_right, -15 * WIDTH / 375.0);
        Bottom(self.contentView.mas_bottom, -7 * HEIGHT / 667.0);
    }];
    
    [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Right(self.contentView.mas_right, -5 * WIDTH / 375.0);
        Bottom(self.contentView.mas_bottom, -12 * HEIGHT / 667.0);
        HequalNum(14);
        WequalNum(32);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        Left(self.contentView.mas_left, 0);
        Right(self.contentView.mas_right, 0);
        Bottom(self.contentView.mas_bottom, 0);
        HequalNum(0.5);
    }];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
